package com.hl.servlet;

import com.alibaba.fastjson.JSON;
import com.hl.bean.PanghuShop;
import com.hl.dao.StoreDao2;
import com.hl.dao.impl.StoreDaoImpl2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.time.LocalDateTime;
//添加门店的连接
@WebServlet("/shop/addShop")
public class AddStoreServlet extends HttpServlet {

    private StoreDao2 storeDao2 = new StoreDaoImpl2();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        Map<String,Object> map = new HashMap<>();
        String shopName = req.getParameter("shopName");
        String shopDescribe = req.getParameter("shopDescribe");
        String shopPhone = req.getParameter("shopPhone");
        String shopProvince = req.getParameter("shopProvince");
        String shopCity = req.getParameter("shopCity");
        String shopDistrict = req.getParameter("shopDistrict");
        String shopAddress = req.getParameter("shopAddress");
        String shopLatitude = req.getParameter("shopLatitude");
        String shopLongitude = req.getParameter("shopLongitude");
        /*LocalDateTime now = LocalDateTime.now();*/
        int row = storeDao2.addStore(new PanghuShop(shopName,shopDescribe,"",shopPhone,shopProvince,shopCity,shopDistrict,shopAddress,shopLongitude,shopLatitude,1,0,"","",0,0));
        System.out.println(row);
        if (row<1){
            map.put("code",302);
            map.put("message","新增失败");
        }else {
            map.put("code",200);
            map.put("message","新增成功");
        }
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
